package com.juc;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;

/**
 * @Author: tgy
 * @Date: 2020-07-27 16:52
 */
public class BlockingQueueTest {

    public static void main(String[] args) throws Exception{

        BlockingQueue blockingQueue = new ArrayBlockingQueue(2);

//        blockingQueue.put(11);
//        blockingQueue.put(11);
//
//        System.out.println(blockingQueue.take());
//        System.out.println(blockingQueue.take());
//        System.out.println(blockingQueue.take());
//        blockingQueue.put(11);

        // add , offer 抛出异常 方法
//        blockingQueue.add(11);
//        blockingQueue.add(11);
//        blockingQueue.add(11);
        blockingQueue.offer(1,3, TimeUnit.SECONDS);
        blockingQueue.offer(11,3, TimeUnit.SECONDS);
        if (blockingQueue.offer(11,3, TimeUnit.SECONDS)){

        }else {

            System.out.println("offer 失败");
        }

        System.out.println(blockingQueue.poll(3, TimeUnit.SECONDS));

    }
}
